using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Practices.EnterpriseLibrary.Data;
using SubSonic;

namespace Commerce.Common
{
    public partial class OrderItemCollection : ActiveList<OrderItem> {
        public OrderItem FindItem(OrderItem item) {
            OrderItem itemOut = null;
            foreach (OrderItem child in this) {
                if (child.ProductID == item.ProductID) {
                    itemOut = child;
                    break;
                }
            }
            return itemOut;
        }

        public new bool Contains(OrderItem item) {
            bool bOut = Find(item.ProductID) != null;
            return bOut;
        }

        public OrderItem Find(int productID) {
            OrderItem result = null;
            foreach (OrderItem child in this) {
                if (child.ProductID == productID) {
                    result = child;
                    break;
                }
            }
            return result;
        }
    }
    
    /// <summary>
    /// A Persistable class that uses Generics to store it's state
    /// in the database. This class maps to the CSK_Store_OrderItem table.
    /// </summary>
    public partial class OrderItem : ActiveRecord<OrderItem>
    {

        #region Custom - not in DB
        int currencyDecimals = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;

        public decimal LineTotal
        {
            get
            {
                decimal dOut = Convert.ToDecimal(this.Quantity) * this.PricePaid;
                return Math.Round(dOut, currencyDecimals);
            }
        }

        private decimal _discountAmount;

        public decimal DiscountAmount
        {
            get
            {
                return _discountAmount;
            }
            set
            {
                _discountAmount = value;
            }
        }

        private DateTime _dateAdded;

        public DateTime DateAdded
        {
            get
            {
                return _dateAdded;
            }
            set
            {
                _dateAdded = value;
            }
        }
        #endregion


    }
}
